local jiaoxi = fk.CreateSkill {
  name = "lingling__jiaoxi",
}

Fk:loadTranslationTable{
  ["lingling__jiaoxi"] = "狡袭",
  [":lingling__jiaoxi"] = "出牌阶段各限一次，你可以将一张牌当【顺手牵羊】对手牌最多的角色使用，或将一张牌当【杀】对没有手牌的角色使用。"..
  "以此法使用的牌无距离和次数限制。",

  ["#lingling__jiaoxi-snatch"] = "狡袭：将一张牌当【顺手牵羊】对手牌最多的角色使用",
  ["#lingling__jiaoxi-slash"] = "狡袭：将一张牌当【杀】对没有手牌的角色使用",
}

jiaoxi:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  prompt = function (self, player, selected_cards, selected)
    return "#lingling__jiaoxi-"..self.interaction.data
  end,
  interaction = function(self, player)
    local all_names = {"snatch", "slash"}
    local names = player:getViewAsCardNames(jiaoxi.name, all_names, nil, player:getTableMark("lingling__jiaoxi-phase"))
    if #names == 0 then return end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = jiaoxi.name
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    use.extraUse = true
    player.room:addTableMark(player, "lingling__jiaoxi-phase", self.interaction.data)
  end,
  enabled_at_play = function(self, player)
    return #player:getViewAsCardNames(jiaoxi.name, {"snatch", "slash"}, nil, player:getTableMark("lingling__jiaoxi-phase")) > 0
  end,
})

jiaoxi:addEffect("prohibit", {
  is_prohibited = function (self, from, to, card)
    if card and to and table.contains(card.skillNames, jiaoxi.name) then
      if card.trueName == "snatch" then
        return table.find(Fk:currentRoom().alive_players, function (p)
          return p:getHandcardNum() > to:getHandcardNum()
        end)
      elseif card.trueName == "slash" then
        return not to:isKongcheng()
      end
    end
  end,
})

jiaoxi:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card, to)
    return card and to and table.contains(card.skillNames, jiaoxi.name)
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and table.contains(card.skillNames, jiaoxi.name)
  end,
})

return jiaoxi
